package com.tju.ocean_ecology_website.service.impl;

import com.tju.ocean_ecology_website.entity.ActivityTag;
import com.tju.ocean_ecology_website.dao.ActivityTagDao;
import com.tju.ocean_ecology_website.service.ActivityTagService;
import org.springframework.stereotype.Service;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.PageRequest;

import javax.annotation.Resource;

/**
 * 活动标签表(ActivityTag)表服务实现类
 *
 * @author shaolong
 * @since 2025-04-29 19:20:49
 */
@Service("activityTagService")
public class ActivityTagServiceImpl implements ActivityTagService {
    @Resource
    private ActivityTagDao activityTagDao;

    /**
     * 通过ID查询单条数据
     *
     * @param id 主键
     * @return 实例对象
     */
    @Override
    public ActivityTag queryById(Long id) {
        return this.activityTagDao.queryById(id);
    }

    /**
     * 分页查询
     *
     * @param activityTag 筛选条件
     * @param pageRequest      分页对象
     * @return 查询结果
     */
    @Override
    public Page<ActivityTag> queryByPage(ActivityTag activityTag, PageRequest pageRequest) {
        long total = this.activityTagDao.count(activityTag);
        return new PageImpl<>(this.activityTagDao.queryAllByLimit(activityTag, pageRequest), pageRequest, total);
    }

    /**
     * 新增数据
     *
     * @param activityTag 实例对象
     * @return 实例对象
     */
    @Override
    public ActivityTag insert(ActivityTag activityTag) {
        this.activityTagDao.insert(activityTag);
        return activityTag;
    }

    /**
     * 修改数据
     *
     * @param activityTag 实例对象
     * @return 实例对象
     */
    @Override
    public ActivityTag update(ActivityTag activityTag) {
        this.activityTagDao.update(activityTag);
        return this.queryById(activityTag.getId());
    }

    /**
     * 通过主键删除数据
     *
     * @param id 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Long id) {
        return this.activityTagDao.deleteById(id) > 0;
    }
}
